<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>修改用户</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<!--导入核心文件-->
		<script src="../../bootstrap3/js/holder.js" type=""></script>
		<link href="../../bootstrap3/css/bootstrap.css" rel="stylesheet" type="text/css">
		<script src="../../bootstrap3/jquery-1.9.1.min.js" type=""></script>
		<script src="../../bootstrap3/js/bootstrap.js" type=""></script>
		<!-- 字体图标 -->
		<link rel="stylesheet" href="../../bootstrap3/font-awesome-4.7.0/css/font-awesome.css"/>
		<link rel="stylesheet" type="text/css" href="../../css/style.css"/>
	</head>

	<body>
		<div id="wrap">
			<div id="top_content">
					<div id="header">
						<div id="rightheader">
							<p>2009/11/20<br /></p>
						</div>
						<div id="topheader">
							<h1 id="title"><a href="#">修改用户信息</a></h1>
						</div>
						<div id="navigation"></div>
					</div>
				<div id="content">
					<p id="whereami"></p>
					<!--<h1>add Role info:</h1>-->
					<form id="form-change-info">
						<table cellpadding="0" cellspacing="0" border="0" class="form_table">
							<tr>
								<td valign="middle" align="right">用户ID:</td>
								<td valign="middle" align="left">
									<input id="inp-adminId" name="adminId" type="text" class="form-control" value="用户ID" readonly="readonly">
								</td>
							</tr>
							<tr>
								<td valign="middle" align="right">登录名:</td>
								<td valign="middle" align="left">
									<input id="inp-adminName" name="adminName" type="text" class="form-control" value="用户名">
								</td>
							</tr>
							<tr>
								<td valign="middle" align="right">昵称:</td>
								<td valign="middle" align="left">
									<input type="text"  placeholder="请输入昵称"name="nickName" class="form-control" id="nickName" readonly="readonly"/>
								</td>
							</tr>
							<tr>
								<td valign="middle" align="right">电话号码:</td>
								<td valign="middle" align="left">
									<input id="inp-phone" name="phone" type="text" class="form-control" placeholder="请输入电话号码" value="电话号码">
								</td>
							</tr>
							<tr>
								<td valign="middle" align="right">性别:</td>
								<td valign="middle" align="left">
										<input id="gender-male" type="radio" name="gender" value="1" checked>男
										<input id="gender-female" type="radio" name="gender" value="0">女
								</td>
							</tr>
							<tr id="tr-Role-list">
								<td valign="middle" align="right">角色:</td>
                                <td valign="middle" align="left">
                                    <input  type="radio" name="role" value="1" checked><span>#{Role}</span>
                                </td>
                                <td valign="middle" align="left">
                                    <input  type="radio" name="role" value="0"><span>#{Role}</span>
                                </td>
                                <td valign="middle" align="left">
                                    <input  type="radio" name="role" value="0"><span>#{Role}</span>
                                </td>
							</tr>
							<tr>
								<td valign="middle" align="right">管理的停车场：</td>
								<td valign="middle" align="left">
									<input type="text"  name="lotName" placeholder="没有停车场" class="form-control"id="inp-lotName" disabled>
								</td>
								<td valign="middle" align="left">
									<select name="showList" class="form-control"  data-province="---- 选择停车场 ----" id="lotName-list"></select>
								</td>
								<td>
									<input type="text" style="visibility: hidden"  name="lotId"  class="form-control"id="inp-lotId" >
								</td>
							</tr>
                            <tr>
								<td valign="middle" align="right">是否启用：</td>
								<td valign="middle" align="left">
                                    <input id="is-use-n" type="radio" name="state" value="0" >否
                                    <input id="is-use-y" type="radio" name="state" value="1">是
								</td>
							</tr>
						</table>
						<p>
							<input type="button" class="cart-del-sel btn btn-default btn-xs" id="btn-chenge-info" onclick="changeInfo()" value="修改"/>
							<input type="reset" class="cart-del-sel btn btn-default btn-xs" value="重置"/>
							<input type="button" class="cart-del-sel btn btn-default btn-xs" value="返回" onclick="location='adminList.html'"/>
						</p>
					</form>
				</div>
			</div>
			<div id="footer">
				<div id="footer_bg">ABC@126.com</div>
			</div>
		</div>
		<script type="text/javascript" src="../../js/jquery-getUrlParam.js"></script>
		<script type="text/javascript">
			$(document).ready(function() {
				showAdminInfo();

				showLotList();
				//为停车场列表绑定改变时事件
				$("#lotName-list").change(function () {
					$("#inp-lotName").val($("#lotName-list").find("option:selected").text());
					$("#inp-lotId").val($("#lotName-list").val());
				});
			});
			function showLotList(){

				$("#lotName-list").append('<option value="0">---请选择修改----</option>');
				$.ajax({
					"url":"/lot/get_lot_list",
					"type":"get",
					"dataType":"json",
					"success":function (json) {
						if(json.state===2000){
							let list = json.data;
							console.log("count"+list.length);
							for (let i = 0; i <list.length ; i++) {
								console.log(list[i].name);
								let op = '<option value="'+list[i].lotId+'">'+list[i].name+'</option>';
								$("#lotName-list").append(op)
							}
						}else{
							alert("获停车场列表失败！"+json.message);
						}
					}
				});
			}
			let adminId = $.getUrlParam("adminId");
			let nums = 0;

			function changeInfo(){
				$.ajax({
					"url": "/admin/change_admin_info",
					"data": $("#form-change-info").serialize(),
					"type": "post",
					"dataType": "json",
					"success": function (json) {
						if (json.state === 2000) {
							alert("修改成功！");
							location.href="adminChangeInfo.html?adminId="+adminId;
						} else {
							alert("修改失败！" + json.message);
						}
					},
					"error": function () {
						alert("您的登录信息已过期！请重新登录");
						//location.href="login.html";
					}
				});
			}


			function showAdminInfo() {
				$.ajax({
					"url":"/admin/get_adminVO_by/"+adminId,
					"type":"get",
					"dataType":"json",
					"success":function(json) {
						if (json.state === 2000) {
							$("#inp-adminId").val(json.data.adminId);
							$("#inp-adminName").val(json.data.adminName);
							$("#inp-phone").val(json.data.phone);
							showAllRoleList();
							console.log("nums:"+nums);
							let str = "#inp-role-";
							let inpRole = new Array();
							let radioGrade = $(str+inpRole[length-1]);
							for (let i=0;i<nums+1;i++){
								inpRole[i] = $(str+i).val();
								console.log("inpRole["+i+"]", ' => ', inpRole[i]);
								if (json.data.adminGrade===inpRole[i]*1){
									radioGrade = $(str+i);
									break;
								}
							}
							radioGrade.prop("checked", "checked");
							$("#inp-lotName").val(json.data.lotName+"("+json.data.lotId+")");
							let radioGender = json.data.gender === 1 ? $("#gender-male") : $("#gender-female");
							radioGender.prop("checked", "checked");
							let radioState = json.data.state === 0 ? $("#is-use-n") : $("#is-use-y");
							radioState.prop("checked", "checked");
						} else {
							alert("读取失败！" + json.message);
						}
					}
				});
			}

			function showAllRoleList() {
				$("#tr-Role-list").empty();
				$.ajax({
					"url": "/role/get_role_all",
					"type": "get",
					"async":false,
					"dataType": "json",
					"success": function (json) {
						if (json.state === 2000) {
							let list = json.data;
							//console.log("count=" + list.length);
							let html = '<td valign="middle" align="right">角色:</td>';
							for (let i = 0; i < list.length; i++) {
								console.log(list[i].roleName);
								html =html + '<td valign="middle" align="left">'+
										'<input  type="radio" id="inp-role-#{num}" name="adminGrade" value="#{adminGrade}"><span>#{roleName}</span>' +
										'</td>'

								html = html.replace(/#{num}/g, i);
								html = html.replace(/#{adminGrade}/g, list[i].adminGrade);
								html = html.replace('#{roleName}', list[i].roleName);
								nums = i;
							}
							$("#tr-Role-list").append(html);
						} else {
							alert("角色列表！" + json.message);
						}
					}
				});
			}

		</script>
	</body>
</html>
